package com.gecba.system.controller;

import com.gecba.system.service.CommonService;
import com.gecba.system.vo.DuplicateCheckVo;
import com.gecba.system.vo.Result;
import com.gecba.system.vo.SelectOptionsVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author chenbo
 */
@Slf4j
@RestController
@RequestMapping("/common")
public class CommonController {

    @Autowired
    private CommonService commonService;

    @PostMapping("/selectOptions")
    public Result<?> selectOptions(@RequestBody SelectOptionsVo selectOptionsVo){
        List<SelectOptionsVo> selectOptionsVos = commonService.selectOptions(selectOptionsVo);
        return Result.OK(selectOptionsVos);
    }

    @PostMapping("/duplicateCheck")
    public Result<?> doDuplicateCheck(@RequestBody DuplicateCheckVo duplicateCheckVo){
        boolean mark = commonService.doDuplicateCheck(duplicateCheckVo);
        if(mark){
            log.info("该值不可用，系统中已存在！");
            return Result.error("该值不可用，系统中已存在！");
        }else {
            return Result.OK("该值可用！");
        }
    }
}
